<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>摄像头测试</title>
</head>

<body>
    <video autoplay controls></video>
</body>
<script>
    
    navigator.mediaDevices.getUserMedia({
        video: {
            height: {
                exact: 360
            }
        },
        audio: true
    }).then((stream => {
        document.querySelector('video').srcObject = stream;
    })).catch(err => {
        alert(`打开摄像头失败`)
        console.err(err);
    })

</script>

</html>